<template>
  <view class="password-login">
    <view class="form">
      <input v-model="username" class="input-view" type="text" placeholder="用户名">
      <input v-model="password" class="input-view" type="password" placeholder="密码">
    </view>
    <button round class="login" type="primary" @click="onLogin">登录</button>
  </view>
</template>

<script>
export default {
  name: 'Login',
  components: {
  },
  data() {
    return {
      username: '',
      password: '',
    }
  },
  onLoad(op) {
    console.log(op)
  },
  methods: {
    onLogin() {
     if (!this.username) {
       uni.showToast({
         icon: 'error',
         title: '请输入用户名'
       })
       return
     }
      if (!this.password) {
        uni.showToast({
          icon: 'error',
          title: '请输入密码'
        })
        return
      }
      if (this.username === 'admin' && this.password === '111') {
        uni.reLaunch({ url: '/pages/home/index' })
      } else {
        uni.showToast({
          icon: 'none',
          title: '用户名或密码错误'
        })
      }
    },
    naviHome() {
      uni.navigateTo({
        url: '/pages/home/index'
      })
    },
    getUserInfo(e) {
      this.authLoading = true
      console.log(e.userInfo || e.target.userInfo)
      this.$store.commit('$uStore', { name: 'vx_t_u_info', value: e.userInfo || e.target.userInfo })
      uni.login({
        provider: 'weixin',
        success: res => {
          if (res.code) {
            this.$store.dispatch('$dLogin', res.code).then(res => {
              if (res.type === false) {
                this.$refs.popup.open('bottom')
              } else if (res.type === true) {
                uni.reLaunch({ url: '/pages/user-center/index' })
              }
            })
          }
        }
      })
    },
    async getPhoneNumber(e) {
      let obj = e.detail || e
      // if (this.hbid) {
      //   obj.hbid = this.hbid
      // }
      if (this.type) {
        obj.type = this.type
      }
      if (obj.errMsg === 'getPhoneNumber:ok') {
        this.$store.dispatch('$dGetPhone', obj).then(res => {
          uni.navigateTo({ url: `/pages/register/index?data=${JSON.stringify(res)}` })
        })
      } else {
        uni.showToast({ title: '您拒绝了授权~,注册失败~' })
      }
    },
    onClose() {
      this.showComplete = false
      this.authLoading = false
    }
  }
}
</script>

<style lang="scss" scoped>
.password-login {
  width: 100vw;
  height: 100vh;
  background-color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.form {
  margin-top: 300rpx;
}
.input-view {
  display: block;
  border-radius: 6rpx;
  width: 600rpx;
  height: 68rpx;
  border: 1px solid #aaaaaa;
  margin-bottom: 60rpx;
  text-indent: 30rpx;
}
.login {
  margin-top: 240rpx;
  font-size: 33rpx;
  width: 465rpx;
  height: 85rpx;
  background: #1E64E1;
  border-radius: 15rpx;
}
.popup-height {
  height: 40vh;
}
.register-popup {
  height: 40vh;
  padding: 30rpx;
  .tips {
    font-size: 36rpx;
    font-weight: bold;
    text-align: center;
  }
  .btn-wrap {
    margin: 30rpx auto;
    display: flex;
    justify-content: center;
  }
  .phone-btn {
    margin-top: 50rpx;
  }
  .no-register {
    font-size: 28rpx;
    color: #3b4144;
  }
  .allow-wrap {
    margin-top: 60rpx;
    text-align: center;
  }
  .allow {
    font-size: 28rpx;
    margin-top: 20rpx;
    color: #909399;
  }
}
</style>
